﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using CrossRoadNS.Model;

namespace CrossRoadNS.Views.UserControls
{
    /// <summary>
    /// Interaction logic for CrossRoadUc.xaml
    /// </summary>
    public partial class CrossRoadUc : UserControl
    {
        public CrossRoadUc()
        {
            InitializeComponent();
        }

        public void Refresh()
        {
            CrossRoad cr = this.DataContext as CrossRoad;

            for (int i = 0; i < cr.height; i++)
            {
                Root.RowDefinitions.Add(new RowDefinition());
            }
            for (int i = 0; i < cr.width; i++)
            {
                Root.ColumnDefinitions.Add(new ColumnDefinition());
            }

            var cellList = cr.Grid.ToList();
            int c = 0;
            for (int i = 0; i < cr.height; i++)
            {
                for (int j = 0; j < cr.width; j++)
                {
                    CellUc celluc = new CellUc();
                    celluc.DataContext = cellList[c];
                    celluc.SetValue(Grid.RowProperty, i);
                    celluc.SetValue(Grid.ColumnProperty, j);
                    this.Root.Children.Add(celluc);
                    c++;
                }
            }
        }
    }
}
